import  pandas as pd
from pyecharts.charts import Bar,Map,Pie
from pyecharts import options as opts
def ditu(data):
   data['公司市地址'] = data['公司地址'].map(lambda x: str(x).split('·')[0])+'市'
   groupby_ = data.groupby(['公司市地址'])[['最高工资']].max()
   x=groupby_.index
   y=groupby_.values
   k=[]
   for i in y:
      k.append(int(i))
   c=(Map()
      .add('中国地图',[list(i) for i in zip(x,k)],maptype='china-cities')
      .set_global_opts(
      title_opts=opts.TitleOpts(title='中国招聘地区最高工资（单位K）',subtitle='数据来自Boss直聘')
      ,visualmap_opts=opts.VisualMapOpts(is_show=True,max_=40,min_=4),
   )
   )
   c.render('地图.html')
   print('地图画完成图')
def zhexiantu(data):
   min = data.groupby(['公司市地址'])[['最低工资']].min().sort_values(by='最低工资',ascending=False).head(10)
   x=min.index
   y=min.values
   k = []
   for i in y:
      k.append(int(i))
   c=(
      Bar(
         init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
               animation_delay=10000,
               animation_easing='elasticOut'
            )
         )
      )
      .add_xaxis([i for i in x])
      .add_yaxis('',[i for i in k])
      .set_global_opts(title_opts=opts.TitleOpts(title='中国招聘地区最低工资中的最低值（单位K）',subtitle='数据来自Boss直聘')
                       ,datazoom_opts=opts.DataZoomOpts(
                                 is_show=True
                                )
                       )
   )
   c.render('柱形图.html')
   print('柱形图画完')
def bitu(data):

   data['公司市地址'] = data['公司地址'].map(lambda x: str(x).split('·')[0]) + '市'
   groupby_ = data.groupby(['需要的经验','学历'])[['需要的经验']].count()
   print(groupby_)
   x = groupby_.index
   y = groupby_.values
   k = []
   for i in y:
      k.append(int(i))
   c=(
      Pie()
      .add("饼图",[list(i) for i in zip(x,k)])
      .set_global_opts(
         title_opts=opts.TitleOpts(
            title='中国招聘关于学历和经验相关的数量'
            ,subtitle='数据来自Boss直聘',
         )
         ,legend_opts=opts.LegendOpts(type_='scroll',pos_left='90%',orient='vertical')
      )
   )
   c.render('饼图.html')
   print('饼图画完')


if __name__ == '__main__':
   data = pd.read_csv('python爬虫招聘信息2.csv')
   index = data[data['工资'].map(lambda x: str(x).find('元/天')) != -1].index
   data = data.drop(index=index)
   index = data[data['工资'].map(lambda x: str(x).find('元/时')) != -1].index
   data = data.drop(index=index)
   data['最低工资'] = data['工资'].map(lambda x: str(x).split('-')[0])

   ks = data['工资'].map(lambda x: str(x).split('-')[1])
   data['最高工资'] = ks.map(lambda x: str(x).split('K')[0])
   ditu(data)
   zhexiantu(data)
   bitu(data)
